﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nwrole.toolbox.sync.entity;
using nwrole.toolbox.sync;

namespace sync_test.action
{
    public class ChananDeploySync
    {
        public static void Run(List<SyncEntity> maps, DateTimeTableSync sync, bool deployGhost = true, bool deployDestination = true)
        {

            Console.WriteLine("Deploy start");
            foreach (var map in maps)
            {
                Run(map, sync, deployGhost, deployDestination);
            }
        }

        public static void Run(SyncEntity map, DateTimeTableSync sync, bool deployGhost = true, bool deployDestination = true)
        {
            try
            {
                System.Console.Write("Deploying " + map.Name + " ....");
                if (deployGhost)
                {
                    DeployGhostInt(map, true, sync);
                }
                if (deployDestination)
                {
                    DeployDestInt(map, sync);
                }
                System.Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

        public static void DeployGhostInt(SyncEntity map, bool drop, DateTimeTableSync sync)
        {
            try
            {
                sync.CreateGhostInt(map, drop);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }


        public static void DeployImportInt(SyncEntity map, DateTimeTableSync sync)
        {
            try
            {
                sync.CreateImportInt(map);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

        public static void DeployDestInt(SyncEntity map, DateTimeTableSync sync)
        {
            try
            {
                sync.CreateDestinationInt(map);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }


    }
}
